package hn.info.hockeynews.helpers;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class ConnectionChecker{
	
	private Context _context;
	public ConnectionChecker(Context con) {
		this._context = con;
	}

	/**
	 * check if internet connection works
	 * */
	public boolean isConnecting() {
		ConnectivityManager cm = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
		if(cm != null) {
			NetworkInfo[] inf = cm.getAllNetworkInfo();
			if(inf != null) {
				for(int i = 0; i < inf.length; i++) {
					if(inf[i].getState() == NetworkInfo.State.CONNECTED) {
						return true;
					}
				}
			}
			return false;
		}
		return false;
	}
}
